package com.lichuang.fruitvarietysm.goods.mapper;

import com.lichuang.fruitvarietysm.goods.entity.Attribute;
import com.lichuang.fruitvarietysm.goods.entity.GoodsSkuAttr;
import com.lichuang.fruitvarietysm.goods.entity.Goodssku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author shuaihang
 * @since 2019-06-05
 */
@Repository
public interface GoodsskuMapper extends BaseMapper<Goodssku> {
    /**
     * 根据商品id查商品是否有sku的值
     * @param goods_id
     * @return
     */
    int sCountGoodSku(@Param("goods_id")Integer goods_id);

    /**
     * 根据商品id，查找对应的sku的值
     * @param goods_id
     * @return
     */
    List<Goodssku> sAttributeValue(@Param("goods_id")Integer goods_id,@Param("attribute_value")String attribute_value);

    /**
     * 根据goodssku表的sku的分割值，查对应的goods_sku_attr表中的值
     * @param id
     * @return
     */
    GoodsSkuAttr sAttName(@Param("id")Integer id);
    /**
     * 根据attribute_id查找对应的attribute表中的名字。
     * @param attribute_id
     * @return
     */
    Attribute sAttributeName(@Param("attribute_id")Integer attribute_id);


    @Select("select sku_attr_name from goods_sku_attr where id = (select sku_attr_pid from goods_sku_attr where id = #{attrId})")
    String selectAttrParentName(Integer attrId);

    @Select("select sku_attr_name from goods_sku_attr where id = #{attrId}")
    String selectAttrName(Integer attrId);
}
